package com.ipc.admin.controller.gwl;

import com.ipc.admin.service.gwl.service.SecondScreenService;
import com.ipc.common.pojo.bo.gwl.PageAndSearchBo;
import com.ipc.common.pojo.vo.R;
import com.ipc.common.util.gwl.NullJudgeUtil;
import com.ipc.core.entity.gwl.SecondScreen;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.jdbc.Null;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/api/secondScreen/")
@Api(tags = "二级诱导屏")
public class SecondScreenController {

    @Resource
    private SecondScreenService service;

    @ApiOperation(value = "新增诱导屏",notes = "新增诱导屏，要求所有信息不能为空")
    @PostMapping("add")
    public R add(@RequestBody @Valid SecondScreen screen, BindingResult result){
        String info = NullJudgeUtil.nullJudge(result);
        if (info != null) {
            return R.fail(info);
        }
        return service.add(screen);
    }

    @ApiOperation(value = "根据ID删除")
    @PostMapping("deleteById")
    public R del(@RequestBody Map<String, Integer> map) {
        return service.del(map.get("id"));
    }


    @ApiOperation(value = "修改信息", notes = "需要ID，文档显示有误！")
    @PostMapping("update")
    public R update(@RequestBody @Valid SecondScreen screen, BindingResult result) {
        String info = NullJudgeUtil.nullJudge(result);
        if (info != null) {
            return R.fail(info);
        }
        return service.update(screen);
    }

    @ApiOperation(value = "根据ID查询诱导屏详情")
    @GetMapping("selectOne")
    public R selectOne(@ApiParam(required = true) int id){
        return service.selectOne(id);
    }

    @ApiOperation(value = "查询所有")
    @GetMapping("selectAll")
    public R page(PageAndSearchBo bo){
        return service.selectAll(bo);
    }


}